<?php

namespace App\Http\Controllers\Manage;

use App\Message;
use Validator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Storage;

class MessageController extends Controller
{
    /**
     * 显示字段
     * @var array
     */
    protected static $field = [
        ['id' => 1 , 'project' => 'LOGO\VI' ],
        ['id' => 2 , 'project' => '品牌整合营销' ],
        ['id' => 3 , 'project' => '包装' ],
        ['id' => 4 , 'project' => '广告' ],
        ['id' => 5 , 'project' => '宣传品' ],
        ['id' => 6 , 'project' => '电商' ],
        ['id' => 7 , 'project' => '工业设计' ],
        ['id' => 8 , 'project' => 'SI' ],
        ['id' => 9 , 'project' => '网站APP开发' ],
        ['id' => 10 , 'project' => '影视' ],
    ];
    /**
     * @var int 数据表id
     */
    public $table_id = 6;

    /**
     * CaseController constructor.
     */
    public function __construct()
    {
        parent::__construct($this->table_id);

    }
    //留言管理

    //留言列表
    public function index() {
        #判断权限
        if($this->rule['view'] == 0){
            return redirect()->back()->withInput()->withErrors('权限不足！');
        }
        $field = self::$field;
        $list = Message::orderBy('id','desc')->paginate(15);
        $total = Message::count();
        return view('manage.message.index',['list' => $list,'field' => $field, 'total' => $total]);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $callback = null;
        #判断权限
        if($this->rule['delete'] == 0){
            return [
                'code' => 101,
                'msg' => '权限不足！'
            ];
        }
        if(Message::destroy($id)) {
            $callback = [
                'code' => 100,
                'msg' => '删除成功！'
            ];
        }
        else {
            $callback = [
                'code' => 101,
                'msg' => '删除失败！'
            ];
        }
        return $callback;
    }
}
